package no.sachmuld.methodcombination.demo;

import no.sachmuld.methodcombination.api.MethodInvocation;
import org.apache.log4j.Logger;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 *
 */
public class LoggingFilterBehaviour extends FilterBehaviour {

    private static Logger logger = Logger.getLogger(LoggingFilterBehaviour.class);

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, MethodInvocation<Void> methodInvocation) throws IOException, ServletException {

        HttpServletRequest req = (HttpServletRequest) request;
        String path = req.getMethod() + " " + req.getServletPath();

        logger.info("before " + path);

        methodInvocation.proceed();

        logger.info("after " + path);

    }
}
